
<?php
require_once '../ptnhuan-web1/libraries/utilites/functions.php';

$path = "../ptnhuan-web1/data/films.txt";

$full_path = realpath($path);

$films = mreadFile($path);
$rating = NULL;
?>
<form name='form1' method="POST">
    <input type="text" name="rating"id="idrating">
    <input type="submit" name="Submit" value="Search">
</form>

<?php if (isset($_POST['Submit'])): ?>
    <?php $rating = (double) $_POST['rating']; ?>
<?php endif; ?>
<?php foreach ($films as $item): ?>
    <?php
    $film = explode(";", $item);
    $img = trim($item[1]);

    ?>
    <?php if (empty($rating)): ?>
<?php if(isset($film[1])|| isset($film[2])|| isset($film[3])):?>
        <img src = '../ptnhuan-web1/public/images/films/<?php echo $film[1] ?>'> 
        <?php echo $film[0] ?>
        <?php echo $film[2] ?>
        <?php echo $film[3] ?>
        <a href='edit.php?if=<?php echo$film[0]?>'>Edit</a>
        <br>
        <?php endif; ?>
    <?php else: ?>
        
        <?php if ($rating < (double) $film[2]): ?>
            <img src = '../ptnhuan-web1/public/images/films/<?php echo $img ?>'>
              <?php echo $film[0] ?>
            <?php echo $film[2] ?>
            <?php if (!empty($film[3])) echo $film[3] ?>
            <br>
            <a href='edit.php?if=<?php echo$film[0]?>'>Edit</a>
        <?php endif; ?>
    <?php endif; ?>

<?php endforeach; ?>   
            